package practica1;

public abstract class FuncionDosVar extends Funcion {
	
	protected double yMin, yMax;
	protected int longX, longY;
	
	abstract public double calcAptitud(double[] f);
	
	public FuncionDosVar(double xMin, double xMax, double yMin, double yMax, double p){
		super(xMin,xMax,p);
		this.yMin = yMin;
		this.yMax = yMax;
		longX = ((int)(Math.ceil((Math.log(1+((xMax-xMin)/precision)))/Math.log(2))));
		longY = ((int)(Math.ceil((Math.log(1+((yMax-yMin)/precision)))/Math.log(2))));
		longCromo = longX + longY;
	}	

	public int getLongX(){
		return longX;
	}
	
	public int getLongY(){
		return longY;
	}
	
	public int getLongCromo() {
		return longX + longY;
	}
	

	public double[] calcFenotipo(boolean[] genes) {
		double[] f = new double[2];
		boolean[] gX = new boolean[longX];
		boolean[] gY = new boolean[longY];
		int j;
		if(genes.length==longX+longY){
			for (int i=0; i<longX; i++) {
				gX[i] = genes[i];
			}
			j=0;
			for (int i=longX; i<longX+longY; i++) {
				gY[j] = genes[i];
				j++;
			}
			f[0] = calcFenotipo(gX,xMin,xMax,longX);
			f[1] = calcFenotipo(gY,yMin,yMax,longY);
		}else{
			System.out.println("Longitud de \"genes\" incorrecta...");
			return null;
		}
		return f;
	}
}
